package com.wan.data.mysql.orm.convert.auto;

import com.wan.data.mysql.orm.convert.AutoConverter;
import com.wan.data.mysql.orm.meta.ColumnMeta;
import com.wan.data.mysql.util.DbColumnType;
import com.wan.util.serializer.FastjsonSerializer;

public class JsonDefaultConverter implements AutoConverter {

    @Override
    public DbColumnType getDbType() {
        return DbColumnType.JSON;
    }

    @Override
    public Object dbToEntity(ColumnMeta columnMeta, Object value) throws Exception {
        return FastjsonSerializer.deserializeStr(value.toString(),columnMeta.getFieldType());
    }

    @Override
    public Object entityToDb(ColumnMeta columnMeta, Object value) {
        return FastjsonSerializer.serializeStr(value);
    }

    @Override
    public Class<?>[] convertType() {
        return new Class[0];
    }
}
